package com.fxl.controller;

import com.fxl.entity.User2;
import com.fxl.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/mybatis")
@Api(value = "用户管理接口", tags = "用户管理接口", description = "用户相关的增删改查操作")
public class MybatisController {

    @Autowired
    private UserService userService;

    @PostMapping("/findAll")
    @ApiOperation(value = "获取所有用户")
    public List<User2> findAll() {
        List<User2> users = userService.findAll();
        return users;
    }

    @PostMapping("/findById")
    @ApiOperation(value = "根据ID获取用户")
    public User2 findById(Integer id) {
        User2 user2 = userService.findById(id);
        return user2;
    }

    @PostMapping("/findByUsername")
    public List<User2> findByUsername(String username) {
        List<User2> users = userService.findByUsername(username);
        return users;
    }

}


